Authentication
signAuthToken
​
A server-side function which creates an auth token to be used to authenticate getLatestPrices requests.
Usage​
Generating authentication tokens on the server:
import { signAuthToken } from '@chronicleprotocol/pull-oracle';
const { token, message } = signAuthToken({
// private key is 0x prefixed 32 byte hex string
privateKey: "0xabc..."
})
Returns​
{
token: "...",
message: {
description: "Chronicle API token",
version: 1,
validFrom: 1730992419,
validTo: 1730994251,
signer: "0x...",
nonce: 1077701,
}
}
token
: the authentication tokenmessage
: the authentication token detailsdescription
: the description of the tokenversion
: the authentication API version numbervalidFrom
: unix timestamp starting from then the token is validvalidTo
: unix timestamp until when the auth token is validsigner
: the address of the signernonce
: unique number
authenticate
​
A client-side function which validates and caches the auth token which was received from the server for future use with getLatestPrices.
Usage​
import { authenticate } from '@chronicleprotocol/pull-oracle';
// token is received from the server
// `authenticate` caches the token in memory so it only needs to be called once per session
authenticate(token);
Returns​
boolean
: whether the provided auth token is currently valid.
isAuthenticated
A function to check whether the library has a currently valid auth token previously cached by the authenticate function.
Usage​
import { isAuthenticated } from '@chronicleprotocol/pull-oracle';
// token from the cache is verified
const isAuthenticated = isAuthenticated()
Returns​
boolean
: whether the cached auth token is currently valid.